package com.yf.activity.controller.dto;

import com.google.common.collect.Lists;
import com.yf.activity.domain.DrMemberFavourable;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@Data
public class UserCouponPojo {

    private Integer id;
    private Integer type;
    private String name;//红包or加息券名称
    private BigDecimal amount;//金额
    private BigDecimal profitAmount;//获得的收益
    private BigDecimal raisedRates;//加息比例
    private BigDecimal enableAmount;//启用金额

    private Integer productDeadline;//产品期限
    private Date expireDate;//开始时间

    public static UserCouponPojo from(DrMemberFavourable memberFavourable) {
        UserCouponPojo pojo = new UserCouponPojo();

        BeanUtils.copyProperties(memberFavourable, pojo);

        return pojo;
    }

    public static List<UserCouponPojo> transform(List<DrMemberFavourable> memberFavourableList) {
        if (memberFavourableList == null)
            return Lists.newArrayList();

        return memberFavourableList.stream()
                .map(UserCouponPojo::from)
                .collect(Collectors.toList());
    }
}
